﻿//-----------------------------------------------------------------------
// <copyright file="IRepository.cs" company="ET">
//     Copyright Mulala. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

namespace Mulala.Cavan.Domain.Seedwork
{
    using System.Collections.Generic;
    using System.Linq;
    using Mulala.Cavan.Core.Persistent;

    /// <summary>
    /// base repository interface
    /// </summary>
    /// <typeparam name="T">entity class</typeparam>
    /// <typeparam name="TSearch">The type of the T search.</typeparam>
    public interface IRepository<T, TSearch>
        where T : class
        where TSearch : class, ISearch
    {
        /// <summary>
        /// Gets the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns>return T</returns>
        T Get(object id);

        /// <summary>
        /// Gets the specified specification.
        /// </summary>
        /// <param name="specification">The specification.</param>
        /// <returns>return T</returns>
        T Get(ISpecification<T, TSearch> specification);

        /// <summary>
        /// Saves the specified model.
        /// </summary>
        /// <param name="model">The model.</param>
        void Save(T model);

        /// <summary>
        /// Updates the specified model.
        /// </summary>
        /// <param name="model">The model.</param>
        void Update(T model);

        /// <summary>
        /// Saves the or update.
        /// </summary>
        /// <param name="model">The model.</param>
        void SaveOrUpdate(T model);

        /// <summary>
        /// Deletes the specified model.
        /// </summary>
        /// <param name="model">The model.</param>
        void Delete(T model);

        /// <summary>
        /// Gets the count.
        /// </summary>
        /// <typeparam name="T">entity class</typeparam>
        /// <returns>long value</returns>
        long GetCount<T>();

        /// <summary>
        /// Gets the count.
        /// </summary>
        /// <param name="specification">The specification.</param>
        /// <returns>long value</returns>
        long GetCount(ISpecification<T, TSearch> specification);

        /// <summary>
        /// Submits the changes.
        /// </summary>
        void SubmitChanges();

        /// <summary>
        /// Gets all.
        /// </summary>
        /// <returns>T list</returns>
        IQueryable<T> GetAll();

        /// <summary>
        /// Gets all.
        /// </summary>
        /// <param name="specification">The specification.</param>
        /// <returns>T list</returns>
        IQueryable<T> GetAll(ISpecification<T, TSearch> specification);

        IList<T> GetPageList(ISpecification<T, TSearch> specification);

        /// <summary>
        /// Gets the page list.
        /// </summary>
        /// <param name="total">The total.</param>
        /// <param name="specification">The specification.</param>
        /// <returns>T page list</returns>
        IList<T> GetPageList(out long total, ISpecification<T, TSearch> specification);

        void CloseSession();
    }
}
